package com.engine4cloud.tdf.supervision.controller.inner;

import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.common.security.annotation.Inner;
import com.engine4cloud.tdf.supervision.dto.create.SpHelpCreateDTO;
import com.engine4cloud.tdf.supervision.dto.query.SpHelpDepartQueryDTO;
import com.engine4cloud.tdf.supervision.dto.query.SpHelpQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.SpHelpResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.SpHelpUpdateDTO;
import com.engine4cloud.tdf.supervision.service.SpHelpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

/**
 * 帮扶申请
 *
 * @author wenjie
 * @date 2024-04-26 14:44:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/inner/help")
@Tag(description = "Help", name = "审批-帮扶申请-inner")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SpHelpInnerController {

    private final SpHelpService helpService;

    /**
     * 分页查询
     *
     * @param dto 帮扶申请
     * @return R<PageInfo < RcglHelpResultDTO>>
     */
    @Inner
    @Operation(summary = "分页查询", description = "分页查询")
    @PostMapping("/page")
    public R<PageInfo<SpHelpResultDTO>> getPageList(@Valid @RequestBody SpHelpQueryDTO dto) {
        return R.ok(helpService.getPageList(dto));
    }

    /**
     * 分页查询
     *
     * @param dto 帮扶申请
     * @return R<PageInfo < RcglHelpResultDTO>>
     */
    @Inner
    @Operation(summary = "分页查询", description = "分页查询")
    @PostMapping("/dept/page")
    public R<PageInfo<SpHelpResultDTO>> getDeptPageList(@Valid @RequestBody SpHelpDepartQueryDTO dto) {
        return R.ok(helpService.getDeptPageList(dto));
    }

    /**
     * 通过id查询帮扶申请
     *
     * @param id id
     * @return R
     */
    @Inner
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<SpHelpResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(helpService.getById(id));
    }

    /**
     * 新增帮扶申请
     *
     * @param dto 帮扶申请
     * @return R
     */
    @Inner
    @Operation(summary = "新增帮扶申请", description = "新增帮扶申请")
    @SysLog("新增帮扶申请")
    @PostMapping
    public R<Boolean> create(@Valid @RequestBody SpHelpCreateDTO dto) {
        return R.ok(helpService.create(dto));
    }

    /**
     * 修改帮扶申请
     *
     * @param dto 帮扶申请
     * @return R
     */
    @Inner
    @Operation(summary = "修改帮扶申请", description = "修改帮扶申请")
    @SysLog("修改帮扶申请")
    @PutMapping
    public R<Boolean> update(@Valid @RequestBody SpHelpUpdateDTO dto) {
        return R.ok(helpService.update(dto));
    }
}